﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;

// Make sure you add references to all three of the Argotic assemblies
using Argotic.Core.Rss;

namespace HelloArgotic
{
    public partial class FormHello : Form
    {
        RssFeed rssFeed;

        public FormHello()
        {
            InitializeComponent();
        }

        private void buttonCheckFeed_Click(object sender, EventArgs e)
        {
            try
            {
                // Create an RSS Feed
                rssFeed = RssFeed.Create(new Uri(this.textBoxRSSFeed.Text));

                // Now you can access properties from the feed
                labelShow.Text = rssFeed.Channel.Description;

                if (rssFeed.Channel.Image != null)
                    this.pictureBoxChannel.ImageLocation = rssFeed.Channel.Image.Url.ToString();
                else
                    this.pictureBoxChannel.ImageLocation = null;

                this.listBoxChannelItems.Items.Clear();

                // Add the items from the channel to a list box
                foreach (RssItem item in rssFeed.Channel.Items)
                {
                    this.listBoxChannelItems.Items.Add(item.Description);
                }
                this.listBoxChannelItems.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Exception: {0}", ex.Message));
            }
        }

        private void listBoxChannelItems_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Display info from the selected items
            RssItem item = rssFeed.Channel.Items[listBoxChannelItems.SelectedIndex];
            this.label3.Text = item.ToString();
        }


    }
}
